import React, { useState, useEffect } from 'react';
export default function tiemhook(future) {
  let timer;
  const [d, setd] = useState();
  const [h, seth] = useState();
  const [m, setm] = useState();
  const [s, sets] = useState();

  let setTime = (future) => {
    //获取当前时间
    let cDate = new Date();
    //获取未来时间
    let fDate = new Date('2022-03-16 00:00:00');
    //时间差
    let cha = fDate - cDate;
    //天
    setd(Math.floor(cha / 1000 / 60 / 60 / 24));
    //小时
    seth(Math.floor((cha / 1000 / 60 / 60) % 24));
    //分
    setm(Math.floor((cha / 1000 / 60) % 60));
    //秒
    sets(Math.floor((cha / 1000) % 60));
    //拼接为字符串// es6模板字符串
  };
  useEffect(() => {
    setTime();
    timer = setInterval(setTime, 1000);
    return () => {
      clearInterval(timer);
    };
  }, []);
  return [d, h, m, s];
}
